package com.sky.roleview.weight;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ImageView;
import androidx.annotation.Nullable;
import com.sky.roleview.entity.RoleSkinInfo;

/**
 * Created by Administrator on 2018/9/11.
 */

public class PlayImageView extends ImageView {
    private OnClickPlayLictener listener;
    private int iconTop, headHeight, bodyHeight, footHeight;

    public PlayImageView(Context context) {
        super(context);
    }

    public PlayImageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public PlayImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    public void setLisnterner(OnClickPlayLictener listener) {
        this.listener = listener;
    }

    public void setData(int iconTop, RoleSkinInfo skinBean) {
        this.iconTop = iconTop;
        headHeight = skinBean.getHeadHeight();//头部高度
        bodyHeight = skinBean.getBodyHeight();//身体高度
        footHeight = skinBean.getFootHeight();//脚高度
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_UP:
                int up_y = (int) event.getY();
                if (up_y > iconTop && up_y < iconTop + headHeight) {
                    //点击头部区域
                    if (listener != null) {
                        listener.onClick(0);
                    }
                } else if (up_y > iconTop + headHeight && up_y < iconTop + headHeight + bodyHeight) {
                    //点击身体区域
                    if (listener != null) {
                        listener.onClick(1);
                    }
                } else if (up_y > iconTop + headHeight + bodyHeight && up_y < iconTop + headHeight + bodyHeight + footHeight) {
                    //点击脚区域
                    if (listener != null) {
                        listener.onClick(2);
                    }
                }
                break;
        }
        return true;
    }

    public interface OnClickPlayLictener {
        void onClick(int type);//0点击头部  1点击身体  2点击脚
    }
}
